<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>乐票航班查询</title>
  </head>
  <body>
    <table>
      <tr>
        <td><div id="flight_query_form" style="height:140px;">
          </div>
        </td>
        <td><div id="my_flight_form" style="height:140px;">
          </div>
        </td>
      </tr>
    </table>
    <div id="flight_grid">
    </div>
    <div id="flight_grid_2">
    </div>
    <br>
    <script>
        var tripType = "";
        var air_no ="";
        var fromto = "";
        var fromto_desc = "";
        var price = "";
        var fly_date = "";
        var fly_time = "";
        var arr_time = "";
        var plane_type = "";
        var position = "";

        var air_no2 = "";
        var fromto2 = "";
        var fromto_desc2 = "";
        var price2 = "";
        var fly_date2 = "";
        var fly_time2 = "";
        var arr_time2 = "";
        var plane_type2 = "";
        var position2 = "";

        var from;
        var to;
        var myFlightStore;
        var trip_type;
        var myFlightData;
        var singleTrip;

        var pNumber;
        var submitMyFlightButton;

        //用于填充我已经确认的航班grid
        function positionReserve(tripType,airNo,Position,planeType,flyDate,flyTime,arrTime,fromtoDesc,Price){
            if(singleTrip.checked){
                var url = "/ticket/addPersonWebOrder?person_number="+pNumber.getValue()+"&air_no="+airNo+"&position="+Position+"&plane_type="+planeType+"&fly_date="+flyDate+"&fly_time="+flyTime+"&arr_time="+arrTime+"&trip_type="+tripType+"&fromto="+from+to+"&fromto_desc="+fromtoDesc+"&price="+Price;
                //var panel = tabs.getActiveTab();
                //panel.getUpdater().update(url);
                //panel.setTitle('订票');
                var newTab = Ext.getCmp('addPersonWebOrder_tab');
                if (newTab) {
                    tabs.activate('addPersonWebOrder_tab');
                    newTab.getUpdater().update(url);
                }
                else {
                    tabs.add({
                        id: 'addPersonWebOrder_tab',
                        title: '定票',
                        //disabled: true,
                        autoLoad: {
                            url: url,
                            scripts: true
                        },
                        closable: true
                    }).show();
                }
            }else{
                if (tripType=="1"){
                    myFlightStore.getAt(0).set("airno",airNo);
                    myFlightStore.getAt(0).set("price",Price);
                    myFlightStore.getAt(0).set("fly_date",flyDate);
                    myFlightStore.getAt(0).set("fly_time",flyTime);
                    myFlightStore.getAt(0).set("plane_type",planeType);

                    air_no = airNo;
                    fromto_desc = fromtoDesc;
                    price = Price;
                    position = Position;
                    fly_date = flyDate;
                    fly_time = flyTime;
                    arr_time = arrTime;
                    plane_type = planeType;
                }else{
                    myFlightStore.getAt(1).set("airno",airNo);
                    myFlightStore.getAt(1).set("price",Price);
                    myFlightStore.getAt(1).set("fly_date",flyDate);
                    myFlightStore.getAt(1).set("fly_time",flyTime);
                    myFlightStore.getAt(1).set("plane_type",planeType);

                    air_no2 = airNo;
                    fromto_desc2 = fromtoDesc;
                    price2 = Price;
                    position2 = Position;
                    fly_date2 = flyDate;
                    fly_time2 = flyTime;
                    arr_time2 = arrTime;
                    plane_type2 = planeType;
                }
            }
            if (myFlightStore.getAt(0).get("airno")!="" && myFlightStore.getAt(1).get("airno")!="" ){
                submitMyFlightButton.enable();
            }
            if (positionWindow != undefined){
                positionWindow.hide();
            }
        }
        /*
         * Ext JS Library 2.2
         * Copyright(c) 2006-2008, Ext JS, LLC.
         * licensing@extjs.com
         *
         * http://extjs.com/license
         */
        //为了一般JS方法可以调用，这个变量定义要放在onReady外面．
        var flightDS;
        var flight2DS;

        var positionCM;
        var positionDS;
        var positionGrid;
        //标记，当前正在操作哪个GRID的联接。
        var current_grid;
        var positionWindow;
        Ext.onReady(function(){
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'side';
            //MyFlight
            //position window
            positionCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '舱位',
                    dataIndex: 'position'
                }, {
                    header: '价格',
                    dataIndex: 'price'
                }, {
                    header: '折扣',
                    dataIndex: 'discount'
                }, {
                    header: '航程',
                    dataIndex: 'fromto_desc',
                    hidden:true
                },{
                    header: "预定",
                    renderer: allPositionReserveRender,
                    dataIndex: 'discount'
                }, {
                    header: '起飞时间',
                    dataIndex: 'fly_time',
                    hidden:true
                }, {
                    header: '起飞时间',
                    dataIndex: 'arr_time',
                    hidden:true
                }]);
            positionDS = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: '/ticket/getAllPositionByAirNo'
                }),
                reader: new Ext.data.JsonReader({
                    root: 'root'
                }, [{
                        name: 'air_no'
                    },{
                        name: 'position'
                    }, {
                        name: 'price'
                    }, {
                        name: 'discount'
                    }, {
                        name: 'fly_date'
                    }, {
                        name: 'fly_time'
                    }, {
                        name: 'arr_time'
                    }, {
                        name: 'fromto_desc'
                    }, {
                        name: 'plane_type'
                    }])
            });
            positionGrid = new Ext.grid.GridPanel({
                ds: positionDS,
                cm: positionCM,
                //collapsible: true,
                animCollapse: false,
                title: '舱位价格列表:',
                loadMask: true
            });

            function allPositionReserveRender(value, cellmeta, record, rowIndex, columnIndex, store){
                var fromto_desc = encodeURIComponent(record.get("fromto_desc"));
                if (singleTrip.checked){
                    return "<a href=# onclick=positionReserve('single','"+record.get("air_no")+"','"+record.get("position")+"','"+record.get("plane_type")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("price")+"')>预订</a>";
                }else{
                    return "<a href=# onclick=positionReserve('"+current_grid+"','"+record.get("air_no")+"','"+record.get("position")+"','"+record.get("plane_type")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("price")+"')>预订</a>";
                }
            }
            //---------position window end-----------

            myFlightData = [['来程航班', air_no, price, fly_date, fly_time, plane_type], ['返/联程航班', air_no2, price2, fly_date2, fly_time2, plane_type2]];
            myFlightStore = new Ext.data.SimpleStore({
                fields: [{
                        name: 'type'
                    }, {
                        name: 'airno'
                    }, {
                        name: 'price'
                    }, {
                        name: 'fly_date'
                    }, {
                        name: 'fly_time'
                    }, {
                        name: 'plane_type'
                    }]
            });
            myFlightStore.loadData(myFlightData);
            var myFlightGrid = new Ext.grid.GridPanel({
                height:95,
                width:380,
                store: myFlightStore,
                title: '已选择的航班',
                columns: [new Ext.grid.RowNumberer(),{
                        id: 'air',
                        header: "类型",
                        width: 60,
                        dataIndex: 'type'
                    }, {
                        header: "航班号",
                        width: 60,
                        dataIndex: 'airno'
                    }, {
                        header: "价格",
                        width: 50,
                        dataIndex: 'price'
                    }, {
                        header: "日期",
                        width: 80,
                        dataIndex: 'fly_date'
                    }, {
                        header: "起飞时间",
                        width: 60,
                        dataIndex: 'fly_time'
                    }, {
                        header: "机型",
                        width: 35,
                        dataIndex: 'plane_type'
                    }]//,
                //stripeRows: true,
                //autoExpandColumn: 'air'
            });
            submitMyFlightButton = new Ext.Button({
                text: "<span class='blue'>确认航班，输入乘客信息</span>",
                handler: submitMyFlight
            })
            submitMyFlightButton.disable();
            function submitMyFlight(){
                if(roundTrip.checked){
                    tripType = "round";
                    fromto = from+to;
                    fromto2 = to+from
                }else if(jointTrip.checked){
                    tripType = "joint";
                    fromto = from+to;
                    fromto2 = to+to2;
                }
                var url = "/ticket/addPersonWebOrder?person_number="+pNumber.getValue()+"&air_no="+air_no+"&position="+position+"&plane_type="+plane_type+"&fly_date="+fly_date+"&fly_time="+fly_time+"&arr_time="+arr_time+"&trip_type="+tripType+"&fromto="+fromto+"&fromto_desc="+fromto_desc+"&price="+price;
                if (roundTrip.checked || jointTrip.checked){
                    url = url + "&air_no2="+air_no2+"&position2="+position2+"&plane_type2="+plane_type2+"&fly_date2="+fly_date2+"&fly_time2="+fly_time2+"&arr_time2="+arr_time2+"&fromto2="+fromto2+"&fromto_desc2="+fromto_desc2+"&price2="+price2;
                }
                var newTab = Ext.getCmp('addPersonWebOrder_tab');
                if (newTab) {
                    tabs.activate('addPersonWebOrder_tab');
                    newTab.getUpdater().update(url);
                }
                else {
                    tabs.add({
                        id: 'addPersonWebOrder_tab',
                        title: '定票',
                        //disabled: true,
                        autoLoad: {
                            url: url,
                            scripts: true
                        },
                        closable: true
                    }).show();
                }
                /*
                var panel = tabs.getActiveTab();
                panel.getUpdater().update(url);
                panel.setTitle('订票');
                */
            }
            var myFlightForm = new Ext.form.FormPanel({
                labelWidth: 65,
                width: 380,
                //frame: true,
                labelAlign: 'right',
                //url: '/ticket/getFlightQueryResult',
                buttonAlign: 'center',
                items:[myFlightGrid],
                buttons:[submitMyFlightButton]
            })
            myFlightForm.render("my_flight_form");

            // fix the bug in codepress - resize
            //Ext.BoxComponent.prototype.setSize('100%', '125px');
            //search Tab
            //end search Tab
            /************************************************************
             * Display the result in page
             * the column model has information about grid columns
             * dataIndex maps the column to the specific data field in
             * the data store (created below)
             ************************************************************/
            //自动出票
            singleTrip = new Ext.form.Radio({
                fieldLabel: '航程类型',
                name: 'trip_type',
                id: 'trip_type_single',
                boxLabel: '单程',
                checked: true,
                inputValue: '单程'
            });
            singleTrip.on('check', function(){
                if (singleTrip.checked) {
                    to2Airport.allowBlank = true;
                    date2Field.allowBlank = true;
                    /*/if (airlaneGridpanel2) {
                        airlaneGridpanel2.setVisible(false);
                    }*/
                    Ext.getCmp('to2_div').hide();
                    Ext.getCmp('date2_div').hide();
                    flight2GridPanel.setVisible(false);
                    flightGridPanel.setHeight(400);
                    myFlightForm.hide();
                    trip_type="single";
                    //----------clear
                    myFlightStore.getAt(0).set("airno","");
                    myFlightStore.getAt(0).set("price","");
                    myFlightStore.getAt(0).set("fly_date","");
                    myFlightStore.getAt(0).set("fly_time","");
                    myFlightStore.getAt(0).set("plane_type","");
                    myFlightStore.getAt(1).set("airno","");
                    myFlightStore.getAt(1).set("price","");
                    myFlightStore.getAt(1).set("fly_date","");
                    myFlightStore.getAt(1).set("fly_time","");
                    myFlightStore.getAt(1).set("plane_type","");

                }
            });

            var roundTrip = new Ext.form.Radio({
                name: 'trip_type',
                id: 'trip_type_round',
                boxLabel: '往返',
                checked: false,
                hideLabel: true,
                inputValue: '往返'
            });
            roundTrip.on('check', function(){
                if (roundTrip.checked) {
                    to2Airport.allowBlank = true;
                    date2Field.allowBlank = false;
                    /*/if (airlaneGridpanel2) {
                        airlaneGridpanel2.setVisible(false);
                    }*/
                    //Ext.getCmp('to2_div').show();
                    Ext.getCmp('to2_div').hide();
                    Ext.getCmp('date2_div').show();
                    flight2GridPanel.setVisible(true);
                    flight2GridPanel.setTitle("返程航班列表");
                    flightGridPanel.setHeight(200);
                    myFlightForm.show();
                    trip_type="round";
                    myFlightStore.getAt(1).set("type","返程航班");
                    myFlightStore.getAt(0).set("airno","");
                    myFlightStore.getAt(0).set("price","");
                    myFlightStore.getAt(0).set("fly_date","");
                    myFlightStore.getAt(0).set("fly_time","");
                    myFlightStore.getAt(0).set("plane_type","");
                    myFlightStore.getAt(1).set("airno","");
                    myFlightStore.getAt(1).set("price","");
                    myFlightStore.getAt(1).set("fly_date","");
                    myFlightStore.getAt(1).set("fly_time","");
                    myFlightStore.getAt(1).set("plane_type","");
                    submitMyFlightButton.disable();
                }
            });
            var jointTrip = new Ext.form.Radio({
                name: 'trip_type',
                id: 'trip_type_joint',
                boxLabel: '联程',
                checked: false,
                hideLabel: true,
                inputValue: '联程'
            });
            jointTrip.on('check', function(){
                if (jointTrip.checked) {
                    to2Airport.allowBlank = false;
                    date2Field.allowBlank = false;
                    /*/if (airlaneGridpanel2) {
                        airlaneGridpanel2.setVisible(false);
                    }*/
                    Ext.getCmp('to2_div').show();
                    Ext.getCmp('date2_div').show();
                    flight2GridPanel.setVisible(true);
                    flight2GridPanel.setTitle("联程航班列表");
                    flightGridPanel.setHeight(200);
                    myFlightForm.show();
                    trip_type="joint";
                    myFlightStore.getAt(1).set("type","联程航班");
                    myFlightStore.getAt(0).set("airno","");
                    myFlightStore.getAt(0).set("price","");
                    myFlightStore.getAt(0).set("fly_date","");
                    myFlightStore.getAt(0).set("fly_time","");
                    myFlightStore.getAt(0).set("plane_type","");
                    myFlightStore.getAt(1).set("airno","");
                    myFlightStore.getAt(1).set("price","");
                    myFlightStore.getAt(1).set("fly_date","");
                    myFlightStore.getAt(1).set("fly_time","");
                    myFlightStore.getAt(1).set("plane_type","");
                    submitMyFlightButton.disable();
                }
            });
            var airportTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{airport_name}({airport_code})', '</div></tpl>');
            var airportStore = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: "/admin/getAllAirportComboBox"
                }),
                reader: new Ext.data.JsonReader({
                    root: 'root'
                }, [{
                        name: 'id'
                    }, {
                        name: 'airport_name'
                    }, {
                        name: 'airport_code'
                    }])
            });
            pNumber = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    reader: new Ext.data.ArrayReader({}, ['value']),
                    data: [['1'], ['2'], ['3'], ['4']]
                }),
                name: 'person_number',
                fieldLabel: "<span class='red'>*</span>乘机人数",
                resiable: true,
                typeAhead: true,
                width: 70,
                handleHeight: 100,
                displayField: 'value',
                valueField: 'value',
                nameField: 'person_number',
                selectOnFocus: true,
                mode: 'local',
                selectOnFocus: true,
                triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                readOnly: true,
                //emptyText: '选择类型...',
                allowBlank: false,
                value:'1'
            });
            var fromAirport = new Ext.form.ComboBox({
                store: airportStore,
                fieldLabel: "<span class='red'>*</span>出发城市",
                name: 'from_airport',
                allowBlank: false,
                blankText: "出发城市必须选择",
                emptyText: '请选择...',
                loadingText: '搜索中...',
                width: 180,
                tpl: airportTpl,
                minChars: 0,
                itemSelector: 'div.search-item',
                onSelect: function(record){
                    fromAirport.setValue(record.data.airport_name);
                    from = record.data.airport_code;
                    if (this.isExpanded()) {
                        this.collapse();
                    }
                }
            });
            fromAirport.on("focus",function(){this.selectText();}); 
            var dateField = new Ext.form.DateField({
                fieldLabel: "<span class='red'>*</span>出发日期",
                name: 'date',
                altFormats: 'Y-m-d',
                format: 'Y-m-d', //格式化日期
                invalidText: "日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                width: 90,
                minValue: today,
                value: today
            });
            var toAirport = new Ext.form.ComboBox({
                store: airportStore,
                fieldLabel: "<span class='red'>*</span>目的城市",
                name: 'to_airport',
                allowBlank: false,
                blankText: "目的城市必须选择",
                emptyText: '请选择...',
                loadingText: '搜索中...',
                width: 180,
                tpl: airportTpl,
                minChars: 0,
                itemSelector: 'div.search-item',
                onSelect: function(record){
                    toAirport.setValue(record.data.airport_name);
                    to = record.data.airport_code;
                    if (this.isExpanded()) {
                        this.collapse();
                    }
                }
            });
            toAirport.on("focus",function(){this.selectText();}); 
            var date2Field = new Ext.form.DateField({
                fieldLabel: "<span class='red'>*</span>联/返日期",
                name: 'date2',
                altFormats: 'Y-m-d',
                format: 'Y-m-d', //格式化日期
                invalidText: "日期格式不对，正确格式为2008-01-01",
                allowBlank: true,
                inputType: '2008-01-01',
                width: 90,
                minValue: today
            });
            var to2Airport = new Ext.form.ComboBox({
                store: airportStore,
                fieldLabel: "<span class='red'>*</span>终到城市",
                name: 'to2_airport',
                allowBlank: true,
                blankText: "终到地城市必须选择",
                emptyText: '请选择...',
                loadingText: '搜索中...',
                width: 180,
                tpl: airportTpl,
                minChars: 0,
                itemSelector: 'div.search-item',
                onSelect: function(record){
                    to2Airport.setValue(record.data.airport_name);
                    to2 = record.data.airport_code;
                    if (this.isExpanded()) {
                        this.collapse();
                    }
                }
            });
            to2Airport.on("focus",function(){this.selectText();}); 
            var searchButton = new Ext.Button({
                text: "<span class='blue'>搜 索 航 班</span>",
                handler: searchFlight
            })
            function searchFlight(){
                // check form value
                this.disable();
                if (flightQueryForm.form.isValid()) {
                    flightDS.baseParams.fromto=from+to;
                    flightDS.baseParams.date=dateField.getValue().format('Y-m-d');
                    flightDS.baseParams.trip_type=trip_type;
                    flightDS.baseParams.person_number=pNumber.getValue();
                    flightDS.reload({callback: function(record, options, success){
                            if (success) {
                                if (!singleTrip.checked) {
                                    reloadDS2();
                                }
                            }
                            else {
                                Ext.Msg.alert('查询异常', '查询中断，请再尝试一次');
                            }
                        }});
                    this.enable();
                }
                else {
                    this.enable();
                    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
            }

            var flightQueryForm = new Ext.form.FormPanel({
                labelWidth: 65,
                width: 450,
                frame: true,
                labelAlign: 'right',
                //url: '/ticket/getFlightQueryResult',
                buttonAlign: 'center',
                items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .3,
                                layout: 'form',
                                border: false,
                                items: [singleTrip]
                            }, {
                                columnWidth: .15,
                                layout: 'form',
                                border: false,
                                items: [roundTrip]
                            }, {
                                columnWidth: .15,
                                layout: 'form',
                                border: false,
                                items: [jointTrip]
                            }, {
                                columnWidth: .4,
                                layout: 'form',
                                border: false,
                                items: [pNumber]
                            }]
                    },{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .6,
                                layout: 'form',
                                border: false,
                                items: [fromAirport]
                            }, {
                                columnWidth: .4,
                                layout: 'form',
                                border: false,
                                items: [dateField]
                            }]
                    },{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .6,
                                layout: 'form',
                                border: false,
                                items: [toAirport]
                            }, {
                                columnWidth: .4,
                                id:'date2_div',
                                layout: 'form',
                                border: false,
                                items: [date2Field]
                            }]
                    },{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .6,
                                id:'to2_div',
                                layout: 'form',
                                border: false,
                                items: [to2Airport]
                            }]
                    }],buttons:[searchButton]})
            flightQueryForm.render("flight_query_form");
            Ext.getCmp('to2_div').hide();
            Ext.getCmp('date2_div').hide();

            var flightCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
                    header: "航空公司",
                    width: 20,
                    dataIndex: 'airways_name'
                }, {
                    header: "航班",
                    width: 20,
                    dataIndex: 'air_no'
                }, {
                    header: "起飞时间",
                    width: 20,
                    dataIndex: 'fly_time'
                }, {
                    header: "到达时间",
                    width: 20,
                    dataIndex: 'arr_time'
                }, {
                    header: "机场",
                    width: 30,
                    dataIndex: 'airport'
                }, {
                    header: "舱位",
                    width: 10,
                    dataIndex: 'position'
                }, {
                    header: "最低价格（元）",
                    width: 20,
                    dataIndex: 'price'
                }, {
                    header: "折扣",
                    width: 20,
                    renderer: discountRender,
                    dataIndex: 'discount'
                }, {
                    header: "飞机型号",
                    width: 30,
                    dataIndex: 'plane_type'
                }, {
                    header: "预定",
                    width: 15,
                    renderer: positionReserveRender,
                    dataIndex: 'plane_type'
                }, {
                    header: "显示所有价格",
                    width: 30,
                    renderer: allPositionRender,
                    dataIndex: 'plane_type'
                }]);
            flightCM.defaultSortable = true;
            function discountRender(value){
                if (value <= 70){
                    return "<span style='color:red;font-weight:bold;'>"+value+"</span>";
                }else{
                    return value ;
                }
            }
            function positionReserveRender(value, cellmeta, record, rowIndex, columnIndex, store){
                //alert("<a href=# onclick=positionReserve('single','"+record.get("air_no")+"','"+record.get("position")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"',encodeURIComponent(\""+record.get("airport")+"\",'"+record.get("price")+"')>预订</a>");
                var fromto_desc = encodeURIComponent(record.get("airport"));
                if (singleTrip.checked){
                    return "<a href=# onclick=positionReserve('single','"+record.get("air_no")+"','"+record.get("position")+"','"+record.get("plane_type")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("price")+"')>预订</a>";
                }else{
                    return "<a href=# onclick=positionReserve('1','"+record.get("air_no")+"','"+record.get("position")+"','"+record.get("plane_type")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("price")+"')>预订</a>";
                }
            }
            function positionReserve2Render(value, cellmeta, record, rowIndex, columnIndex, store){
                //alert("<a href=# onclick=positionReserve('single','"+record.get("air_no")+"','"+record.get("position")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"',encodeURIComponent(\""+record.get("airport")+"\",'"+record.get("price")+"')>预订</a>");
                var fromto_desc = encodeURIComponent(record.get("airport"));
                return "<a href=# onclick=positionReserve('2','"+record.get("air_no")+"','"+record.get("position")+"','"+record.get("plane_type")+"','"+date2Field.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("price")+"')>预订</a>";
            }
            function allPositionRender(value, cellmeta, record, rowIndex, columnIndex, store){
                var fromto_desc = encodeURIComponent(record.get("airport"));
                return "<a href=# onclick=allPositionWindow(1,'"+record.get("air_no")+"','"+dateField.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("plane_type")+"')>"+record.get("air_no")+"所有价格</a>"
            }
            function allPosition2Render(value, cellmeta, record, rowIndex, columnIndex, store){
                var fromto_desc = encodeURIComponent(record.get("airport"));
                return "<a href=# onclick=allPositionWindow(2,'"+record.get("air_no")+"','"+date2Field.getValue().format('Y-m-d')+"','"+record.get("fly_time")+"','"+record.get("arr_time")+"','"+fromto_desc+"','"+record.get("plane_type")+"')>"+record.get("air_no")+"所有价格</a>"
            }
            /************************************************************
             * connect to backend - grid - core part
             * create the Data Store
             *   connect with backend and list the result in page
             *   through JSON format
             ************************************************************/
            flightDS = new Ext.data.Store({
                // load using script tags for cross domain, if the data in on the same domain as
                // this page, an HttpProxy would be better
                proxy: new Ext.data.HttpProxy({
                    url: '/ticket/getFlightQueryResult'
                }),
                // create reader that reads the Topic records
                reader: new Ext.data.JsonReader({
                    root: 'root'//,
                    //totalProperty: 'totalProperty',
                    //id: 'id'
                }, [{ name: 'airways_name'
                    }, {
                        name: 'position'
                    }, {
                        name: 'fly_time'
                    }, {
                        name: 'arr_time'
                    }, {
                        name: 'air_no'
                    }, {
                        name: 'airport'
                    }, {
                        name: 'price'
                    }, {
                        name: 'discount'
                    }, {
                        name: 'plane_type'
                    }])
            });

            /************************************************************
             * Define menubar now in here
             *   add and delete functions
             ************************************************************/
            /************************************************************
             * define grid panel now
             ************************************************************/
            var flightGridPanel = new Ext.grid.GridPanel({
                border: false,
                el: 'flight_grid',
                ds: flightDS,
                cm: flightCM,
                autoWidth: true,
                viewConfig: {
                    forceFit: true
                },
                loadMask: true,
                iconCls: 'icon-grid',
                //collapsible: true,
                animCollapse: false,
                //frame: true,
                title: '航班列表',
                height:450
            });

            //panel render
            flightGridPanel.render();
            // trigger the data store load
            //flightDS.load();

            /************************************************************
             * Action - edit
             *   handle double click
             *   user select one of the item and want to update it
             ************************************************************/
            flightGridPanel.on('rowdblclick', function(customerGridPanel, rowIndex, e){
                var selectedId = flightDS.data.items[rowIndex].id;
            });

            //gird2
            var flight2CM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
                    header: "航空公司",
                    width: 20,
                    dataIndex: 'airways_name'
                }, {
                    header: "航班",
                    width: 20,
                    dataIndex: 'air_no'
                }, {
                    header: "起飞时间",
                    width: 20,
                    dataIndex: 'fly_time'
                }, {
                    header: "到达时间",
                    width: 20,
                    dataIndex: 'arr_time'
                }, {
                    header: "机场",
                    width: 30,
                    dataIndex: 'airport'
                }, {
                    header: "舱位",
                    width: 10,
                    dataIndex: 'position'
                }, {
                    header: "最低价格（元）",
                    width: 20,
                    dataIndex: 'price'
                }, {
                    header: "折扣",
                    width: 20,
                    renderer: discountRender,
                    dataIndex: 'discount'
                }, {
                    header: "飞机型号",
                    width: 30,
                    dataIndex: 'plane_type'
                }, {
                    header: "预定",
                    width: 15,
                    renderer: positionReserve2Render,
                    dataIndex: 'plane_type'
                }, {
                    header: "显示所有价格",
                    width: 30,
                    renderer: allPosition2Render,
                    dataIndex: 'plane_type'
                }]);
            flight2CM.defaultSortable = true;
            /************************************************************
             * connect to backend - grid - core part
             * create the Data Store
             *   connect with backend and list the result in page
             *   through JSON format
             ************************************************************/
            flight2DS = new Ext.data.Store({
                // load using script tags for cross domain, if the data in on the same domain as
                // this page, an HttpProxy would be better
                proxy: new Ext.data.HttpProxy({
                    url: '/ticket/getFlightQueryResult'
                }),
                // create reader that reads the Topic records
                reader: new Ext.data.JsonReader({
                    root: 'root'//,
                    //totalProperty: 'totalProperty',
                    //id: 'id'
                }, [{ name: 'airways_name'
                    }, {
                        name: 'position'
                    }, {
                        name: 'fly_time'
                    }, {
                        name: 'arr_time'
                    }, {
                        name: 'air_no'
                    }, {
                        name: 'airport'
                    }, {
                        name: 'price'
                    }, {
                        name: 'discount'
                    }, {
                        name: 'plane_type'
                    }])
            });

            /************************************************************
             * Define menubar now in here
             *   add and delete functions
             ************************************************************/
            /************************************************************
             * define grid panel now
             ************************************************************/
            var flight2GridPanel = new Ext.grid.GridPanel({
                border: false,
                el: 'flight_grid_2',
                ds: flight2DS,
                cm: flight2CM,
                autoWidth: true,
                viewConfig: {
                    forceFit: true
                },
                loadMask: true,
                iconCls: 'icon-grid',
                //collapsible: true,
                animCollapse: false,
                //frame: true,
                title: '航班列表',
                height:200
            });

            //panel render
            flight2GridPanel.render();
            flight2GridPanel.setVisible(false);
            myFlightForm.hide();
            // trigger the data store load
            //flightDS.load();

            /************************************************************
             * Action - edit
             *   handle double click
             *   user select one of the item and want to update it
             ************************************************************/
            //往返或联程
            function reloadDS2(){
                if (trip_type=="round"){
                    flight2DS.baseParams.fromto = to+from;
                }else{
                    flight2DS.baseParams.fromto = to+to2;
                }
                flight2DS.baseParams.date = date2Field.getValue().format("Y-m-d");
                flight2DS.baseParams.person_number = pNumber.getValue();
                //ds2.baseParams.zhida_checkbox = zhida_checkbox;
                //flight2DS.baseParams.airways_code = airways_code;
                flight2DS.baseParams.trip_type = trip_type;
                flight2DS.reload({
                    callback: function(record, options, success){
                        if (success) {
                            //Ext.Msg.alert('操作','成功!!');
                            //处理前一天,后一天时间和标题.
                            //upDate2.setText("前一天(" + getDateByNum(fly_date2, -1) + ")");
                            //nextDate2.setText("后一天(" + getDateByNum(fly_date2, 1) + ")");
                        }
                        else {
                            Ext.Msg.alert('查询异常', '联程查询中断，请再尝试一次');
                        }
                    }
                });
            }
        });

        function allPositionWindow(gridNo,airNo,fly_date,fly_time,arr_time,fromto_desc,plane_type){
            current_grid = gridNo;
            positionDS.baseParams.fromto_desc = fromto_desc;
            positionDS.baseParams.air_no = airNo;
            positionDS.baseParams.fly_date = fly_date;
            positionDS.baseParams.fly_time = fly_time;
            positionDS.baseParams.arr_time = arr_time;
            positionDS.baseParams.plane_type = plane_type;
            positionDS.baseParams.person_number = pNumber.getValue();
            if (singleTrip.checked){
                positionDS.baseParams.from = from;
            }else{
                if (current_grid==1){
                    positionDS.baseParams.from = from;
                }else{
                    positionDS.baseParams.from = to;
                }
            }
            positionDS.removeAll();
            positionDS.reload();
            positionWindow = new Ext.Window({
                title: "航班："+airNo+" 起飞日期："+fly_date+" 起飞时间："+fly_time+" 起降机场："+decodeURIComponent(fromto_desc),
                width: 510,
                height: 360,
                minWidth: 510,
                minHeight: 360,
                layout: 'fit',
                plain: true,
                bodyStyle: 'padding:5px;',
                buttonAlign: 'center',
                items: [positionGrid],
                modal: true,
                buttons: [ {
                        text: '关 闭',
                        handler: function(){
                            positionWindow.hide();
                        }
                    }]
            });
            positionWindow.show();
        }
    </script>
  </body>
</html>
